<template>
  <view class="bg-white p3">
    <view class="pb3 text-16px font-bold">提现明细</view>
    <view v-if="!loading">
      <view v-if="list.length > 0 ">
        <view v-for="(item, key) in list" :key="key" class="flex items-center justify-between p2" style="border-bottom: 1px solid #f6f6f6">
          <view class="">
            <view>￥ {{ item.money }}</view>
            <view class="text-12px text-gray">{{ item.create_time }}</view>
          </view>
          <view class="text-12px font-bold">
            <text v-if="item.status === '0'">提现中</text>
            <text v-if="item.status === '1'" class="text-green">已提现</text>
            <text v-if="item.status === '-1'" class="text-red">提现失败</text>
            <text v-if="item.status === '-2'" class="text-gray">提现冻结</text>
          </view>
        </view>
        <u-loadmore v-if="finish" status="nomore" />
        <u-loadmore v-else status="loadmore" @loadmore="getUserWithdrawalList()" />
      </view>
      <view v-else class="h-20vh w-full flex items-center justify-center bg-white">
        <u-empty text="当前暂无数据" />
      </view>
    </view>
    <view v-else class="h-20vh w-full flex items-center justify-center bg-white">
      <u-loading-icon />
    </view>
  </view>
</template>

<script>
import { getUserWithdrawalList } from '~/api/user'
import bus from '~/uni_modules/dk-diy-page/utils/bus'

export default {
  name: 'DkAppFundList',
  props: {
    buttonText: {
      type: String,
      default: '提现',
    },
    buttonAmount: {
      type: Number,
      default: 1,
    },
    buttonColor: {
      type: String,
      default: '#FE2C55',
    },
  },
  data() {
    return {
      list: [],
      page: 1,
      size: 10,
      total: 0,
      loading: true,
      finish: false,
    }
  },
  mounted() {
    this.getUserWithdrawalList()
    bus.on('refreshFund', () => {
      this.list = []
      this.page = 1
      this.getUserWithdrawalList()
    })
  },
  methods: {
    getUserWithdrawalList(page){
      this.page = page || this.page
      getUserWithdrawalList(this.page, this.size).then((res) => {
        this.total = res.data.total
        this.list = this.list.concat(res.data.list)
        this.comment = res.data.info
        this.loading = false
        this.page++
        if (this.list.length >= this.total || res.data.list.length <= 0){
          this.finish = true
        }
      }).catch(() => {})
    },
  },
}
</script>

<style scoped></style>
